from typing import Any
from tools.weather_tool import fetch_weather, format_weather
from tools.car_tool import fetch_car_enter, format_car_enter
from tools.decoal_tool import decoal_car
from tools.fuel_jump import jump_url
from tools.pyecharts_tool import echarts_bar_url, echarts_pair_url, echarts_table_url
from tools.report_tool import find_home_quantity_price, format_quantity_price
import os
from client import MCPClient
client = MCPClient()
UPLOAD_FOLDER = 'upload_audio'

async def query_car (beginInTime: str, endInTime: str) -> str:
    data = await fetch_car_enter(beginInTime, endInTime)
    enter_data = format_car_enter(data)
    print("🚀 ~ enter_data:", enter_data)
    if not data:
        return "⚠️ 无法获取天气信息"
    return enter_data

async def query_quantity_price (beginInTime: str, endInTime: str) -> str:
    data = await find_home_quantity_price(beginInTime, endInTime)
    enter_data = format_quantity_price(data)
    print("🚀 ~ enter_data:", enter_data)
    if not data:
        return "⚠️ 无法获取天气信息"
    return enter_data

async def queryData():
    os.environ['FUEL_TOKEN'] = 'e462399b-31c1-46b7-bee5-ce65c1b5d42c'
    strData = await jump_url('全水检测')
    print("🚀 ~ strData:", strData)

async def test_echarts_bar_url():
    data = await echarts_bar_url(['蒙', ' 湘', '冀'], [{'name': '数量', 'data': [50, 30, 6]}],'入厂次数')
    print("🚀 ~ data:", data)

async def test_echarts_table_url():
    headles = ['煤场名称', '入库量', '出库量', '库存量']
    rows =[['一期中北煤场', 20567.02, 0.0, 76206.78], ['一期北煤场', 25.65, 0.0, 120082.65], ['一期南煤场', 100.0, 0.0, 68435.77], ['一期中南煤场', 0.0, 0.0, 3830.78], ['三期中北煤场', 0.0, 0.0, 31485.63], ['三期北煤场', 0.0, 0.0, 49000.63], ['三期南煤场', 0.0, 0.0, 39432.41], ['三期中南煤场', 0.0, 0.0, 79471.43], ['呼热东煤场', 268.27, 66.66, 11370.79], ['呼热西煤场', 108.6, 0.0, 17367.41], ['五期北煤场', 24.23, 0.0, 28894.28], ['五期中北煤场', 134.0, 16500.0, 35342.87], ['五期中南煤场', 0.0, 0.0, 45144.27], ['五期南煤场', 0.0, 0.0, 30982.91]]
    title = '本月汽车入厂数据'
    data = await echarts_table_url(headles, rows, title)
    print("🚀 ~ data:", data)

async def test_audio_to_text():
    UPLOAD_PATH = os.path.abspath(UPLOAD_FOLDER)
    audio_file_path = os.path.join(UPLOAD_PATH, 'recording.wav')
    resule = client.audio_to_text(audio_file_path)
    print("🚀 ~ data:", resule)
    
def main():
    import asyncio
    # asyncio.run(query_quantity_price('2025-04-21 00:00:00', '2025-04-21 23:59:59'))
    # asyncio.run(test_audio_to_text())
    asyncio.run(test_echarts_table_url())
    

if __name__ == "__main__":
    main()